package com.masterclient.app.modules.aftersale.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.baselib.container.CommonBaseResponse;
import com.eoner.baselibrary.bean.aftersale.AfterSalePurchaseListData;
import com.masterclient.app.httpservice.RetrofitUtil2;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;

/**
 * @auther hjian
 * @date 2020/9/29.
 */
public class AfterSalePurchaseListPresenter extends AfterSalePurchaseListContract.Presenter {
    @Override
    public void getAfterSaleListBean(int page) {
        mRxManager.add(toSubscribe(RetrofitUtil2.getInstance().afterSalePurchaseList(String.valueOf(page),"20"), new Consumer<CommonBaseResponse<AfterSalePurchaseListData>>() {
            @Override
            public void accept(@NonNull CommonBaseResponse<AfterSalePurchaseListData> bean) throws Exception {
                if(bean.getCode() == 0){
                    mView.showData(bean.getData());
                }else {
                    mView.showFailure(bean.getMsg());
                }
            }
        },new ThrowableConsumer(){
            @Override
            public void accept(Throwable o) throws Exception {
                o.printStackTrace();
                mView.showFailure("网络异常，请重试");
            }
        }));
    }
}
